package com.lei.retrofitfactory_one.http.factory;

import com.lei.retrofitfactory_one.http.product.BaseRetrofitNetworkProduct;
import com.lei.retrofitfactory_one.http.product.BaseRetrofitUploadProduct;
import com.lei.retrofitfactory_one.http.product.IRetrofitProduct;
import com.lei.retrofitfactory_one.http.url.ClassType;

/**
 * @ProjectName : YoHuo001Java
 * @Author : 雷金泷
 * @Time : 2020/12/27 18:43
 * @Description : 文件描述
 */
public class BaseRetrofitFactory implements IRetrofitFactory {
    private static BaseRetrofitFactory instance = new BaseRetrofitFactory();
    private static BaseRetrofitNetworkProduct baseRetrofitNetworkProduct = new BaseRetrofitNetworkProduct();
    private static BaseRetrofitUploadProduct baseRetrofitUploadProduct = new BaseRetrofitUploadProduct();

    @Override
    public IRetrofitProduct createRetrofit(ClassType type) {
        switch (type){
            case NETWORK:
                return baseRetrofitNetworkProduct;
            default:
                return baseRetrofitUploadProduct;
        }
    }

    public static  <T> T create(ClassType type,Class<T> service) {
        return instance.createRetrofit(type).getRetrofit().create(service);
    }
}
